﻿using SQLServer.BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using Tenancy.Helper;

namespace Tenancy.Server
{
    /// <summary>
    /// Hbung_HignWorkList 的摘要说明
    /// </summary>
    public class Hbung_HignWorkList : IHttpHandler
    {
        Machine Mac = new Machine();
        /// <summary>
        /// 高空作业平台列表接口
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
           
            //页数
            string CurPage = context.Request.Params["PageIndex"];
            if (string.IsNullOrEmpty(CurPage))
            {
                context.Response.Write(GenerClass.SetParamErrorJsData("PageIndex值为空"));
                return;
            }
            int Indexnum = 0;
            if (!string.IsNullOrEmpty(CurPage))
            {
                if (!int.TryParse(CurPage, out Indexnum) || Indexnum < 0)
                {
                    context.Response.Write(GenerClass.SetParamErrorJsData("PageIndex值不是数字"));
                    return;
                }
            }
            //每页多少数据
            string ageSize = context.Request.Params["PageSize"];
            int Sizenum = 0;
            if (string.IsNullOrEmpty(ageSize))
            {
                context.Response.Write(GenerClass.SetParamErrorJsData("pageSize值为空"));
                return;
            }
            if (!string.IsNullOrEmpty(ageSize))
            {
                if (!int.TryParse(ageSize, out Sizenum) || Sizenum < 0)
                {
                    context.Response.Write(GenerClass.SetParamErrorJsData("pageSize值不是数字"));
                    return;
                }
            }
            string strWhere = " ProductType='A' and status='待租' ";
            //机型，（剪刀式(Scissor)，直臂式(Straight)，曲臂式(Bend)，其它(Other) ）
            string HB_Type = context.Request.Params["Type"];
            if(!string.IsNullOrEmpty(HB_Type))
            {
                strWhere += string.Format(" and AMachineClass='{0}' ", HB_Type);
            }
            //品牌
            string HB_Brand = context.Request.Params["Brand"];
            if (!string.IsNullOrEmpty(HB_Brand))
            {
                strWhere += string.Format(" and brand='{0}'", HB_Brand);
            }
            //型号
            string HB_Version = context.Request.Params["Version"];
            if (!string.IsNullOrEmpty(HB_Version))
            {
                strWhere += string.Format(" and modelCode='{0}'", HB_Version);
            }
            //平台高度
            string HB_Platform = context.Request.Params["Platform"];
            if (!string.IsNullOrEmpty(HB_Platform))
            {
                strWhere += string.Format(" and PlatformHeight='{0}'", HB_Platform);
            }
            //驱动方式
            string HB_DriverWay = context.Request.Params["DriverWay"];
            if (!string.IsNullOrEmpty(HB_DriverWay))
            {
                strWhere += string.Format(" and DriveWay='{0}'", HB_DriverWay);
            }
            //停放地
            string HB_ParkingPlace = context.Request.Params["ParkingPlace"];
            if (!string.IsNullOrEmpty(HB_ParkingPlace))
            {
                strWhere += string.Format(" and ParkAddressCurProvince='{0}'", HB_ParkingPlace);
            }
            //模糊查询条件
            //string HB_Condition = context.Request.Params["Condition"];
            //if (!string.IsNullOrEmpty(HB_Condition))
            //{
            //    strWhere += string.Format(" and ( brand like '%{0}%' or modelCode like '%{0}%' or PlatformHeight like '%{0}%' or DriveWay like '%{0}%' or ParkAddressCurProvince '%{0}%' or ParkAddressCurCity like '%{0}%' or ParkAddressCurCounty like '%{0}%' or ParkAddressCurDetail like '%{0}%' ) ");
            //}
            DataTable HighPT = Mac.IEHighList(strWhere, Indexnum, Sizenum, "id");

            context.Response.Write(GenerClass.GetJsonTable("查询成功", JsonHelper.DataTableToJSON(HighPT)));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}